package com.odp.mapper;

import com.odp.entity.Post;
import com.odp.entity.PostDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PostMapper {

    //新建帖子
    public int addPost(Post post);

    //点赞帖子
    @Update("update t_post set likes =likes+1 where post_id=#{postId}")
    public int likePost(int postId);

    //获取帖子偏好
    @Select("select perfer_id from t_post where post_id=#{postId}")
    public int getPerferIdByPostId(int postId);

    //有人评论  帖子回复数+1   帖子未读数+1
    @Update("update t_post set reply_num=reply_num+1 , unread_num=unread_num+1 where post_id=#{postId}")
    public int postBeCommented(int postId);


    //有人回复层主，帖子表中未读数+1 帖子回复数+1
    @Update("update t_post set unread_num=unread_num+1,reply_num=reply_num+1 where post_id=#{postId}")
    public int reply4Post(int postId);

    //查询符合偏好的20个帖子  +  随机不重复的10个帖子（不与前面的20个帖子重复的）
    public List<Post> get30Posts(@Param("perferIds") List<Integer> perferIds);

    //根据帖子id获得帖子
    public Post getPostById(int postId);
}
